<template>
  <div class="tpl43-swiper">
    <!-- 折叠轮播 -->
    <div ref="getHeight"  class="imgAdv-box">
      <!-- TODO 小程序端用swiper -->
      <wx-swiper class="my-swipe" :style="`height: ${imgadvWxH}`" :circular="true" indicator-color="#ebedf0" indicator-active-color="#FE5000" :autoplay="autoplay" :indicator-dots="showIndicators">
        <wx-swiper-item v-for="(item,index) in tplItemData.dataset_swipe" :key="index">
          <a @click="openLink(item.link)">
            <img :src="item.pic" alt="" @load="onImageLoad($event)"/>
          </a>
        </wx-swiper-item>
      </wx-swiper>
    </div>
    <section class="list-menu" v-if="tplItemData.dataset_btn">
      <ul>
        <li v-for="(item,index) in tplItemData.dataset_btn" :key="index">
          <a @click="openLink(item.link)">
            <img :src="item.pic"/>
            <p>{{item.showtitle}}</p>
          </a>
        </li> 
      </ul>
    </section>
  </div>
</template>

<script>
import Vue from 'vue'
import { openPage } from '@/utils/utils'

export default Vue.extend({
  props: {
    tplItemData: {
      type: Object // 传入参数的类型
    }
  },
  data() {
    return {
      imgadvWxH: '0',
      showIndicators: true,
      autoplay: true,
    }
  },
  methods: {
    // TODO 小程序跳转
    openLink(link) {
      openPage(link)
    },
    // TODO 小程序swiper获取图片高度
    onImageLoad(event){
      const imgHeight = event.detail.height
      if(imgHeight > parseFloat(this.imgadvWxH)){
        this.imgadvWxH = imgHeight+'px'
      }
    }
  },
})
</script>

<style lang="scss">
@import "src/styles/mixin";
.tpl43-swiper{
  .imgAdv-box{
    img{
      width: 100%;
    }
    .van-swipe__indicators{
      bottom: 27.5%;
      .van-swipe__indicator{
        width: 10px;
        height: 10px;
        background: #fff;
        border-radius: 5px;
        &.van-swipe__indicator--active{
          width: 28px;
        }
      }
    }
  }
  .list-menu {
    position: relative;
    margin-top: -27%;
    margin-bottom: 2%;
    ul{
      display: flex;
      flex-wrap: wrap;
      flex-direction: row;
      justify-content: space-between;
      background: #fff;
      margin: 0 20px;
      padding: 7% 2% 3%;
      border-radius: 20px;
      text-align: center;
      li {
        width: 17%;
        text-align: center;
        margin: 0 4% 3.5%;
        img{
          width: 100%;
          height: 110px;
        }
        p {
          padding-top: 10px;
          color: #666;
          @include lineClamp(24px,30px,1)
        }
      }
    }
  }
}
</style>